//
//  UIImageView+Extension.swift
//  SwiftExercise
//
//  Created by 罗宗庆 on 2021/6/23.
//

import UIKit

extension UIImageView{
    
    ///设置圆角图片
    func circleImage(){
        //建立上下文
        UIGraphicsBeginImageContextWithOptions(self.frame.size, false, 0)
        //获取当前上下文
        let ctx = UIGraphicsGetCurrentContext()
        
        //添加一个圆  并裁减
        ctx?.addEllipse(in: self.bounds)
        ctx?.clip()
        
        //绘制
        self.draw(self.bounds)
        
        //获取绘制的图像
        let image = UIGraphicsGetImageFromCurrentImageContext()
        //关闭上下文
        UIGraphicsEndImageContext()
        DispatchQueue.global().async {
            self.image = image
        }
        
    }
}
